﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using l1cs.server.model.Instance;
using l1cs.server.model;

namespace l1cs.server.serverpackets
{
    public class S_UseArrowSkill : ServerBasePacket
    {
        private static Logger _log = Logger.getLogger( typeof( S_UseArrowSkill ).FullName );

        private static AtomicInteger _sequentialNumber = new AtomicInteger( 0 );

        private byte[] _byte = null;

        public S_UseArrowSkill( L1Character cha, int targetobj, int spellgfx, int x, int y, bool isHit )
        {
            int aid = 1;
            // オークアーチャーのみ変更
            if ( cha.getTempCharGfx() == 3860 )
            {
                aid = 21;
            }
            writeC( Opcodes.S_OPCODE_ATTACKPACKET );
            writeC( aid );
            writeD( cha.getId() );
            writeD( targetobj );
            writeC( isHit ? 6 : 0 );
            writeC( cha.getHeading() );
            // writeD(0x12000000);
            // writeD(246);
            writeD( _sequentialNumber.incrementAndGet() );
            writeH( spellgfx );
            writeC( 127 ); // スキル使用時の光源の広さ？
            writeH( cha.getX() );
            writeH( cha.getY() );
            writeH( x );
            writeH( y );
            // writeC(228);
            // writeC(231);
            // writeC(95);
            // writeC(82);
            // writeC(170);
            writeC( 0 );
            writeC( 0 );
            writeC( 0 );
            writeC( 0 );
            writeC( 0 );
        }

        override
        public byte[] getContent()
        {
            if ( _byte == null )
            {
                _byte = _bao.ToArray();
            }
            else
            {
                int seq = _sequentialNumber.incrementAndGet();
                _byte[12] = (byte)( seq & 0xff );
                _byte[13] = (byte)( seq >> 8 & 0xff );
                _byte[14] = (byte)( seq >> 16 & 0xff );
                _byte[15] = (byte)( seq >> 24 & 0xff );
            }
            return _byte;
        }

        override
        public String getType()
        {
            return "[S] S_UseArrowSkill";
        }

    }
}